Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf milestone and measurement updates for minecraft #10309

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eanders-ms
Copy link
Contributor

@eanders-ms eanders-ms commented Dec 6, 2024

Adds three new extension points for sharing telemetry with the target:

  • onPerfMilestone
  • onPerfMeasurement
  • onPostHostMessage (for sharing ticks and tutorial events)

In addition:

  • Updated milestones and measurements to accept parameters.
  • Factored out milestone and measurement string literals.
  • Added a few more measurements, most notably we now measure pxt.U.requestAsync.

@eanders-ms eanders-ms requested a review from a team December 6, 2024 01:41
@@ -38,20 +38,50 @@ namespace pxt {
let eventLogger: TelemetryQueue<string, Map<string>, Map<number>>;
let exceptionLogger: TelemetryQueue<any, string, Map<string>>;

type EventListener<T = any> = (payload: T) => void;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the purpose of having a generic here if we're setting it to any?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any is just a default type, effectively making the type optional. Some event sources might not want to pass a parameter. I do provide an explicit type in the instances below (via createEventSource).

// performance measuring, added here because this is amongst the first (typescript) code ever executed
export namespace perf {
let enabled: boolean;

export const onMilestone = createEventSource<{ milestone: string, time: number, params?: Map<string> }>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we wouldn't want a type for event sources? I know these two objects have differences, but is there a foundation we would want to have for event sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They do have a type, it's the type returned by createEventSource. I think I don't understand the question. Can you clarify?

}
report += `\n`
}
durations[msg] = duration;
}
console.log(report)
enabled = false; // stop collecting milestones and measurements after report
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In doing a quick skim, it looks like enabled is otherwise only getting set at the initialization of the perf loading. If this is the case, will it be possible to grab more reports after the webapp first loading?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this change because I believe it is undesirable to continue collecting perf measurements after the perf report is generated. These measurements accumulate in memory over time and never flush, which is bad if left unbounded (which it was). These metrics are most useful for gauging startup performance, so I think we don't want to continue collecting them once the editor is fully loaded. Let me know if I'm mistaken!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, these are pretty generic methods. I worry someone might want to use them down the line (to measure issues with perf when hitting the play button, for example) and get confused as to why they're not working.

Maybe we could have a flag to control this behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thsparks I agree it could be useful beyond startup. Supporting this would require coming up with a flushing strategy beyond what exists today. That's out of scope of this change.

pxt.analytics.trackPerformanceReport();
}
pxt.perf.recordMilestone(Milestones.EditorContentLoaded);
if (!this.autoRunOnStart()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this no longer nested?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to send this milestone to minecraft regardless of whether the project being loaded is a tutorial.

Copy link
Contributor

@thsparks thsparks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few comments, nothing major. Looks good on the whole!

docfiles/pxtweb/cookieCompliance.ts Outdated Show resolved Hide resolved
export let startTimeMs: number;
export let stats: {
// name, start, duration
durations: [string, number, number][],
durations: [string, number, number, Map<string>?][],
// name, event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// name, event
// name, event, params

}
report += `\n`
}
durations[msg] = duration;
}
console.log(report)
enabled = false; // stop collecting milestones and measurements after report
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, these are pretty generic methods. I worry someone might want to use them down the line (to measure issues with perf when hitting the play button, for example) and get confused as to why they're not working.

Maybe we could have a flag to control this behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants